package com.len.service;

import com.len.base.BaseMapper;
import com.len.base.impl.BaseServiceImpl;
import com.len.entity.SpGoods;
import com.len.mapper.SpGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SpGoodsService extends BaseServiceImpl<SpGoods,String> {
    @Autowired
    private SpGoodsMapper spGoodsMapper;

    @Override
    public BaseMapper<SpGoods, String> getMappser() {
        return spGoodsMapper;
    }

    /**
     * 商品库存-1
     * @param id 商品ID
     */
    public void changeNum(String id){
        //获取该商品
        SpGoods spGoods = this.selectByPrimaryKey(id);
        String num = spGoods.getTbGoodsNum();
        //商品数量-1
        String subNum = String.valueOf((Integer.valueOf(num)-1));
        spGoodsMapper.changeNum(subNum,id);
    }
    /**
     * 商品库存+1
     * @param id 商品ID
     */
    public void changeNumadd(String id){
        //获取该商品
        SpGoods spGoods = this.selectByPrimaryKey(id);
        String num = spGoods.getTbGoodsNum();
        //商品数量-1
        String subNum = String.valueOf((Integer.valueOf(num)+1));
        spGoodsMapper.changeNum(subNum,id);
    }
    public void updateto(String  user, String id){
        spGoodsMapper.updateto(user, id);
    }
    /**
     * 库存是否为0
     * @param id 商品ID
     * @return
     */
    public boolean exit(String id){
        SpGoods spGoods = this.selectByPrimaryKey(id);
        if(spGoods.getTbGoodsNum().equals("0")){
            return true;
        }else {
            return false;
        }
    }

    public List<Map> getProductByType(String date, String type){
        return spGoodsMapper.getProductByType(date,type);
    }
    public SpGoods selectId(String id){
        return spGoodsMapper.selectId(id);
    }
    public void updatePrice(double price, String id){
        spGoodsMapper.updatePrice(price,id);
    }
    public Map selectId2(String id){
        return spGoodsMapper.selectIds(id);
    }
    public int insert1(SpGoods spGoods){
        return spGoodsMapper.insert1(spGoods);
    }
}
